package com.project.service;

import com.project.bean.UserBean;
import com.project.dao.IUserDao;
import com.project.dao.impl.UserDaoImpl;
import com.project.server.Request;
import com.project.server.Response;
import com.project.server.Servlet;
import com.project.server.WebServlet;

/**
 * 按ID查询用户业务组件
 */
@WebServlet("findById")
public class FindByIdService implements Servlet {
    private IUserDao userDao = new UserDaoImpl();

    public void service(Request request, Response response){
        //得到表单数据
        int id = Integer.parseInt(request.getParameter("id"));

        //调用持久方法，得到id对应的对象
        UserBean user = userDao.findById(id);
        String str = "<form action='update' method='get'>";
        str += "<input type='hidden' name='id' value='"+id+"'>";
        str += "用户名："+user.getName()+"<br>";
        str += "密码：<input type='password' name='pwd'><br>";
        str += "生日："+user.getBirthday()+"<br>";
        str += "工资：<input type='text' name='money' value='"+user.getMoney()+"'><br>";
        str += "<input type='submit' value='修改'>";

        str += "</form>";

        response.sendMessage(str);
    }
}